package IP;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class test {
    public static void main(String[] args){
        try {
            InetAddress[] name =InetAddress.getAllByName("www.baidu.com");//给定主机的名称，根据系统上配置的名称服务返回其IP地址数组
            for (InetAddress inetAddress : name) {
                System.out.println(inetAddress);
                System.out.println(inetAddress.getHostAddress());//获取ip地址字符串
                System.out.println(inetAddress.getAddress());//根据提供的主机名和IP地址创建InetAddress。
                System.out.println(inetAddress.getCanonicalHostName());//获取此IP地址的完全限定域名
                System.out.println(inetAddress.getHostName());//获取此IP地址的主机名。
            }


            System.out.println(InetAddress.getByName("www.baidu.com"));//确定主机名称的IP地址。
            byte[] ipdz = {(byte) 183, (byte) 232, (byte) 231, (byte) 172};
            System.out.println(InetAddress.getByAddress(ipdz));//原始IP地址创建InetAddress对象。
            System.out.println(InetAddress.getByAddress("www.baidu.com",ipdz));//原始IP地址创建InetAddress对象


        } catch (UnknownHostException e) {
            e.printStackTrace();
        }


    }
}
